package com.bigdata.core.transformations

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * zipWithIndex
 * 将RDD和数据下标 index 压缩成一个K,V格式的RDD
 * index 从0开始
 */
object Demo25_zipWithIndex {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("zip")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val rdd1 = sc.parallelize(List[String]("a", "b", "c"), 2)
    val result: RDD[(String, Long)] = rdd1.zipWithIndex()
    result.foreach(println)
  }
}
